<?php
/**
 * 页面 - JBlog
 * 
 * @copyright (c) 2008-2010 JBlog (www.lisijie.org)
 * @author lisijie <lisijie86@gmail.com>
 * @version $Id$
*/

!defined('IN_JBLOG') && exit('Access Denied!');

if ( $get['id'] ) {
	$_ENV['post'] = get_post($get['id']);
} elseif ( $get['alias'] ) {
	$_ENV['post'] = get_post($get['alias'], 'alias');	
} else {
	error_404();
}

if ( empty($_ENV['post']) || $_ENV['post']['status'] != 1 ) {
	show_msg('页面不存在。');
}

if ( $_ENV['post']['comments'] ) {
	query_comment($_ENV['post']['id'], config('comment_limit'));
}

$view = false;
if ($post_views = get_cookie('post_views')) {
	$postids = explode(',',$post_views);
	if (in_array($get['id'], $postids)) {
		$view = true;
	}
}
if (!$view) {
	$db->query("UPDATE ".tname('post')." SET views = views + 1 WHERE id = '".$get['id']."'");
	$post_views .= empty($post_views) ? $_ENV['post']['id'] : ','.$_ENV['post']['id'];
	set_cookie('post_views', $post_views);
}

$keywords = post('title',true).post('tags',true);
$description = post('excerpt', true);
$description = str_replace(array(' ',"\r","\n","\t"),'',strip_tags($description));

blog('title', post('title',true));
blog('keywords', $keywords);
blog('description', cut_str($description,255));

if ( is_file(THEME_ROOT.$_ENV['post']['type'].'.php') ) {
	template($_ENV['post']['type']);
} else {
	template('post');
}
?>